﻿namespace Smart.Utils.Net
{
    using System;
    using System.Data;

    public class SendMail
    {
        private string path;

        public SendMail()
        {
        }

        public SendMail(string path)
        {
            this.path = path;
        }

        public string getEmail()
        {
            DataSet set = new DataSet();
            set.ReadXml(this.path ?? "");
            return set.Tables["EMAIL"].Rows[0]["Address"].ToString();
        }

        public static bool Send(string subject, string content)
        {
            try
            {
                Email email = new Email("webmaster@Smart.com.vn", "Smart Co Ltd");
                email.AssignGmailSSL("webmaster@Smart.com.vn", "webmaster");
                email.Content(subject, content);
                email.Send();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool Send1(string subject, string content)
        {
            try
            {
                Email email = new Email("webmaster@Smart.com.vn", "Smart Co Ltd");
                email.AddToAddress("webmaster@Smart.com.vn", "Support Customer");
                email.AssignGmailSSL("webmaster@Smart.com.vn", "webmaster");
                email.Content(subject, content);
                email.Send();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool Send1(string UserID, string password, string subject, string content, string App)
        {
            try
            {
                Email email = new Email(UserID, App + " Contact");
                email.AddToAddress(UserID, App + " Contact");
                email.AssignGmailSSL(UserID, password);
                email.Content(subject, content);
                email.Send();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool Send2(string from, string yourname, string UserID, string password, string subject, string content, string App)
        {
            try
            {
                Email email = new Email(from, yourname);
                email.AddToAddress(UserID, App + " Contact");
                email.AssignGmailSSL(UserID, password);
                email.Content(subject, content);
                email.Send();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}

